<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>
</head>
<body>
	<table id="storage_dg" title="仓库列表" class="easyui-datagrid"
		style="width: 100%; height: 480px"
		url="${param.request.contextPath}/storage/list"
		toolbar="#storage_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<!--  field字段需要与返回数据的属性名一致 -->
				<th field="storageId" align="center">仓库编号</th>
				<th field="storageName" width="50">仓库名称</th>
				<th field="storageAddress" width="50">仓库地址</th>
				<th field="storageCapacity" width="50">仓库容量</th>
				<th field="storageCurrent" width="50">当前容量</th>
				<th field="cordon" width="50">警戒线</th>
				<!-- <th field="brandPhoto" formatter="imageFormatter" align="center"
					width="50" height="45">品牌图片</th> -->
			</tr>
		</thead>
	</table>

	<div id="storage_toolbar">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" onclick="newStorage()">新增</a> <a
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-edit" plain="true" onclick="editStorage()">修改</a> <a
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true" onclick="destroyStorage()">删除</a>
		</div>
		<div>
			&nbsp;仓库名称： <input type="text" id="storageSearch" size="20"
				onkeydown="if(event.keyCode == 13) search()" /> <a
				href="javascript:search()" class="easyui-linkbutton"
				iconCls="icon-search" plain="true">搜索</a>
		</div>
	</div>

	<div id="storage_dlg" class="easyui-dialog"
		style="width: 700px; height: 480px; padding: 10px 20px" closed="true"
		buttons="#storage_dlg-buttons">
		<div class="ftitle">信息管理</div>
		<form id="storage_fm" enctype="multipart/form-data" method="post">
			<div class="fitem">
				<label>仓库名称:</label> <input name="storageName"
					class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>仓库地址:</label> <input name="storageAddress"
					class="easyui-validatebox">
			</div>
			<div class="fitem">
				<label>仓库容量:</label> <input name="storageCapacity"
					class="easyui-validatebox">
			</div>
			<div class="fitem">
				<label>当前容量:</label> <input name="storageCurrent"
					class="easyui-validatebox">
			</div>
			<div class="fitem">
				<label>警戒线:</label> <input name="cordon" class="easyui-validatebox">
			</div>

		</form>
	</div>

	<div id="storage_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="save()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#storage_dlg').dialog('close')">取消</a>
	</div>


	<script type="text/javascript">
		function newStorage() {
			$('#storage_dlg').dialog('open').dialog('setTitle', '新增管理');
			$('#storage_fm').form('clear');
			url = '${pageContext.request.contextPath}/storage/add';
		}

		function editStorage() {
			$('#storage_fm').form('clear');
			var row = $('#storage_dg').datagrid('getSelected');
			if (row) {
				$('#storage_dlg').dialog('open').dialog('setTitle', '修改管理');
				$('#storage_fm').form('load', row);
				url = '${pageContext.request.contextPath}/storage/edit?storageId='
						+ row.storageId;
			}
		}

		function save() {
			$('#storage_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Info',
							msg : result.errorMsg
						});
					}

					$('#storage_dlg').dialog('close'); // close the dialog
					$('#storage_dg').datagrid('reload'); // reload the user data
				}
			});
		}

		function destroyStorage() {
			var row = $('#storage_dg').datagrid('getSelected');
			if (row) {
				$.messager
						.confirm(
								'Confirm',
								'确认删除?',
								function(r) {
									if (r) {
										$
												.post(
														'${pageContext.request.contextPath}/storage/delete',
														{
															storageId : row.storageId
														},
														function(result) {
															if (result.success) {
																$('#storage_dg')
																		.datagrid(
																				'reload'); // reload the user data
															} else {
																$.messager
																		.show({ // show error message
																			title : 'Error',
																			msg : result.errorMsg
																		});
															}
														}, 'json');
									}
								});
			}
		}

		function imageFormatter(value, row, index) {
			return "<img  width='45' height='45' src='${pageContext.request.contextPath}/"+value+"'>";
		}

		function search() {
			$("#storage_dg").datagrid('load', {
				"storageName" : $("#storageSearch").val()
			});
			url = '${param.request.contextPath}/storage/list';
		}
	</script>

</body>
</html>